home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1320 / 1320.xpi / chrome / gmanager.jar / content / options / dialogs / account.js next >
Text File  |  2010-01-22  |  5KB  |  141 lines

  1. // Gmail Manager
  2. // By Todd Long <longfocus@gmail.com>
  3. // http://www.longfocus.com/firefox/gmanager/
  4.  
  5. var gmanager_OptionsAccount = new function()
  6. {
  7.   this.__proto__ = new gmanager_BundlePrefix("gmanager-options-");
  8.   
  9.   this.load = function()
  10.   {
  11.     // Unwrap the window arguments
  12.     if ("arguments" in window && window.arguments.length > 0)
  13.     {
  14.       // window.arguments[0] : manager
  15.       // window.arguments[1] : email
  16.       
  17.       this._manager = window.arguments[0];
  18.       this._email = window.arguments[1];
  19.       
  20.       if (this._email)
  21.         this._account = this._manager.getAccount(this._email);
  22.       else
  23.         this._account = this._manager.defaultAccount;
  24.     }
  25.     
  26.     // Check if the account is specified
  27.     if (!this._account)
  28.     {
  29.       // Close the dialog
  30.       window.close();
  31.     }
  32.     
  33.     var toolbar = document.getElementById("gm-prefs-toolbar-toolbar-id");
  34.     var toolbars = gmanager_Utils.getToolbars();
  35.     
  36.     for (var i = 0; i < toolbars.length; i++)
  37.     {
  38.       var menuitem = document.createElement("menuitem");
  39.       menuitem.setAttribute("label", toolbars[i].id);
  40.       menuitem.setAttribute("value", toolbars[i].id);
  41.       toolbar.appendChild(menuitem);
  42.     }
  43.     
  44.     // Display the email (if available)
  45.     document.getElementById("gmanager-options-account-email").value = this._account.email;
  46.     document.getElementById("gmanager-options-account-email").disabled = this._email;
  47.     
  48.     // Display the alias
  49.     var alias = this._account.node.getAttribute("alias");
  50.     document.getElementById("gmanager-options-account-alias").value = (alias ? alias : "");
  51.     
  52.     // Display the password
  53.     var password = this._account.node.getAttribute("password");
  54.     document.getElementById("gmanager-options-account-password").value = (password ? password : "");
  55.     
  56.     // Load the page preferences
  57.     gmanager_Prefs.loadPrefs(this._account.node, document);
  58.     
  59.     this.input();
  60.   }
  61.   
  62.   this.input = function()
  63.   {
  64.     // Account
  65.     document.getElementById("gmanager-options-account-alias").disabled = (document.getElementById("gmanager-options-account-email").value == "");
  66.     document.getElementById("gmanager-options-account-password").disabled = (document.getElementById("gmanager-options-account-email").value == "");
  67.     
  68.     // Toolbar display
  69.     var isToolbar = document.getElementById("gm-prefs-toolbar-display").checked;
  70.     document.getElementById("gm-prefs-toolbar-toolbar-id").parentNode.disabled = !isToolbar;
  71.     document.getElementById("gm-prefs-toolbar-placement").disabled = !isToolbar;
  72.     document.getElementById("gm-prefs-toolbar-specific-position").disabled = (!isToolbar || document.getElementById("gm-prefs-toolbar-placement").value != "specific-position");
  73.     
  74.     // Check messages
  75.     var isCheck = document.getElementById("gm-prefs-notifications-check").checked;
  76.     document.getElementById("gm-prefs-notifications-check-interval").disabled = !isCheck;
  77.     
  78.     // Sounds
  79.     var isSound = document.getElementById("gm-prefs-notifications-sounds").checked;
  80.     document.getElementById("gm-prefs-notifications-sounds-file").disabled = !isSound;
  81.     document.getElementById("gm-prefs-notifications-sound-browse").disabled = !isSound;
  82.     document.getElementById("gm-prefs-notifications-sound-preview").disabled = (!isSound || (isSound && document.getElementById("gm-prefs-notifications-sounds-file").value == ""));
  83.   }
  84.   
  85.   this.selectSoundFile = function()
  86.   {
  87.     var path = gmanager_Sounds.selectFile();
  88.     if (path)
  89.       document.getElementById("gm-prefs-notifications-sounds-file").value = path;
  90.   }
  91.   
  92.   this.previewSoundFile = function()
  93.   {
  94.     gmanager_Sounds.play(document.getElementById("gm-prefs-notifications-sounds-file").value);
  95.   }
  96.   
  97.   this.dialogAccept = function()
  98.   {
  99.     var email = document.getElementById("gmanager-options-account-email").value;
  100.     var alias = document.getElementById("gmanager-options-account-alias").value;
  101.     var password = document.getElementById("gmanager-options-account-password").value;
  102.     
  103.     // Check if the email is valid
  104.     if (email.search(/^.+@.+\..+$/) == -1)
  105.     {
  106.       // The email is not valid
  107.       alert(gmanager_Bundle.getString("gmanager-login-valid-email"));
  108.       
  109.       // Keep the dialog open
  110.       return false;
  111.     }
  112.     
  113.     // Save the page preferences
  114.     gmanager_Prefs.savePrefs(this._account.node, document);
  115.     
  116.     if (this._account && this._email)
  117.     {
  118.       // Update the account alias and password
  119.       this._account.node.setAttribute("alias", alias);
  120.       this._account.node.setAttribute("password", password);
  121.     }
  122.     else
  123.     {
  124.       // Create the account
  125.       var account = this._manager.addAccount("gmail", email, alias, password, this._account.node);
  126.       
  127.       // Check if the account was created
  128.       if (!account)
  129.       {
  130.         // The email already exists
  131.         alert(this.getString("email-exists"));
  132.         
  133.         // Keep the dialog open
  134.         return false;
  135.       }
  136.     }
  137.     
  138.     // Close the dialog
  139.     return true;
  140.   }
  141. }